#ifndef SHOPPINGCARTDIALOG_H
#define SHOPPINGCARTDIALOG_H

#include <QDialog>
#include <QMap>

// Forward declarations
class QTableWidget;
class QLabel;
class QPushButton;
struct DrinkNode; // From backend/drink.h
struct OrderNode; // From backend/order.h (needed for saving)

class ShoppingCartDialog : public QDialog
{
    Q_OBJECT

public:
    // Constructor takes cart items, user ID, and the full drink list for lookups
    explicit ShoppingCartDialog(const QMap<int, int>& cartItems,
                                int userId,
                                DrinkNode* drinkList, // Pass the loaded drink list
                                QWidget *parent = nullptr);
    ~ShoppingCartDialog();

signals:
    // Signal emitted after a successful order placement
    void orderPlacedSuccessfully();

private slots:
    void populateCartTable();
    void calculateTotal();
    void handleConfirmOrder();

private:
    void setupUi();

    QTableWidget *cartTable;
    QLabel *totalPriceLabel;
    QPushButton *confirmButton;
    QPushButton *cancelButton;

    // Data passed from OrderingPanel
    QMap<int, int> m_cartItems; // Key: drinkId, Value: quantity
    int m_userId;
    DrinkNode* m_drinkListHead; // Pointer to the full drink list (don't free here)

    // Internal data
    float m_totalPrice = 0.0f;
    OrderNode* m_newOrdersHead = nullptr; // Temp list for new orders before saving
};

#endif // SHOPPINGCARTDIALOG_H